﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using MaLu.Framework.Common;
using MaLu.BusiLogic;
using MaLu.Common;
using System.Data;

namespace MaluJg.web.ProjectFund
{
    public partial class Item4v : ProjectPage1
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {
            string projectname = string.Empty;
            string content = BLProject.GetProjectItem(Provider, ProjectID, "item4.aspx", ref projectname);
            if (content != string.Empty)
            {
                XmlDocument document = new XmlDocument();
                document.LoadXml(content);
                XmlElement xe = document.SelectSingleNode("//附件列表") as XmlElement;
                tbAttachIDs.Text = Util.ReturnXml(xe.InnerText);
                DataTable dtAtt = BLAttach.GetAttachList(Provider, tbAttachIDs.Text);
                foreach (DataRow item in dtAtt.Rows)
                {
                    tbAttaches.Text += string.Format("<li id=\"{0}\" ><a target=\"_blank\" href=\"../common/GetAttach.aspx?id={0}\">{1}</a>&nbsp;&nbsp;</li>", item["AttachmentID"].ToString(), item["DisplayFileName"].ToString());
                }


            }
        }

        private string FillContent()
        {
            string template = BLProject.GetTemplate(Provider, "item4.aspx");
            if (template != string.Empty)
            {

                XmlDocument document = new XmlDocument();
                document.LoadXml(template);
                XmlElement xe = document.SelectSingleNode("//附件列表") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbAttachIDs.Text.Trim());
                

                return document.OuterXml;
            }
            else
                return string.Empty;

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            BLProject.SaveProjectItem(Provider, ProjectID, "item4.aspx", FillContent());


            string msg = "已保存!";

            string script = "<script>alert('" + msg + "');location.href=location.href;</script>";
            ClientScript.RegisterStartupScript(this.GetType(), "Close", script);

            //string script = "<script>window.opener.document.getElementById('btnRefresh').click();window.close();</script>";
            //ClientScript.RegisterStartupScript(this.GetType(), "Close", script);
        }
    }
}
